<script setup lang="ts">

/*========================================>( 父传子属性 )<========================================*/
const props = defineProps(['isToolPadShow', 'covers', 'activeIndex'])
/*========================================>( 子传父属性 )<========================================*/
const emits = defineEmits(['change'])


/*========================================>( 监听方法 )<========================================*/
//监听点击封面
const handleCoverClick = (index: number, item: any) => {
    if (index === props.activeIndex) return
    emits('change', {
        seriesId: item.id,
        seriesIndex: index
    })
}

//监听拖动触发
const handleMove = (index: number) => {
    emits('change', {
        seriesIndex: index
    })
}

/*========================================>( 钩子 )<========================================*/
onMounted(async () => {

})
</script>
<template>
    <div class="component-container image-selector">
        <div class="title">序列</div>
        <div class="box">
            <div class="cover" v-for="item, index in props.covers" :key="index"
                :class="{ active: props.activeIndex === index }" @click="handleCoverClick(index, item)">
                <div class="image" v-if="item.url" :style="{ backgroundImage: `url(${item.url})` }"></div>
                <div class="image-und" v-else>
                    <svg-icon icon-class="image" width="50" height="50" style="color:#ccc" />
                </div>
                <div class="index-view">{{ index + 1 }}</div>
                <div class="image-count">{{ item.length }}<svg-icon icon-class="images" width="15" height="15"
                        style="color:#999;padding-bottom:2px;" /></div>
                <div class="name" v-dragSeries="{ type: 'resource', img: item.coverImg ?? '', call: () => handleMove(index) }" :data-series-id="item.id">
                    <p class="p-r-5-5" :data-series-id="item.id">{{ item.name }}</p>
                </div>
            </div>
            <div class="vh-30"></div>
        </div>
    </div>
</template>
<style lang="scss"></style>
<style lang="scss" scoped>
.component-container.image-selector {
    position: relative;
    border-right: solid 2px #ccc;
    border-left: solid 2px #ccc;
    border-bottom: solid 2px #ccc;
    height: calc(100vh - 140px);
    width: 150px;

    .title {
        width: 100%;
        height: 30px;
        line-height: 30px;
        text-align: center;
        color: #ccc;
        border-bottom: solid 1px #666;
    }

    .box {
        margin-top: 10px;
        width: 100%;
        height: calc(100vh - 30px);
        overflow-y: auto;

        .cover {
            position: relative;
            width: 120px;
            height: 120px;
            border: solid 2px #3d3d3d;
            // background-color: #000;
            margin: 5px auto;
            cursor: pointer;

            &:hover {
                border: solid 2px #666;

                & .name {
                    color: #ccc;
                }
            }

            &.active {
                border: solid 2px #99CCFF;

                .index-view {
                    background-color: #99CCFF;
                    color: #000;
                    font-weight: bold;
                }
            }

            .index-view {
                position: absolute;
                top: 0;
                left: 0;
                z-index: 1;
                width: 18px;
                height: 18px;
                line-height: 18px;
                background-color: #003366;
                color: #e1e1e1;
                text-align: center;
                font-size: 12px;
            }

            .image-count {
                position: absolute;
                top: 3px;
                right: 4px;
                z-index: 1;
                width: 40px;
                height: 18px;
                color: #999;
                text-align: right;
                font-size: 12px;
            }

            .image {
                width: 100%;
                height: 100%;
                background-position: center;
                background-size: 90% 90%;
                background-repeat: no-repeat;
                background-color: #000;
            }

            .image-und {
                width: 100%;
                height: 100%;
                display: flex;
                justify-content: center;
                align-items: center;
                background-color: #000;
            }

            .name {
                position: absolute;
                width: 100%;
                height: 100%;
                bottom: 0;
                left: 0;
                color: #666;
                text-align: left;
                font-size: 12px;
                display: flex;
                justify-content: center;
                align-items: center;
                white-space: normal;
                word-break: break-all;
            }
        }


        &::-webkit-scrollbar {
            width: 3px;
            background-color: #3d3d3d;
        }

        &::-webkit-scrollbar-thumb {
            background-color: #99CCFF;
        }

        direction: rtl;
    }

}</style>